class MyBlockingQueue{
    private String[] elems = null;
    private int head;
    private int tail;
    private int size;

    public MyBlockingQueue(int capacity){
        elems = new String[capacity];
    }

    void put(String elem)
    {
        if(size>=elem.length()){
            //队列满
            return;
        }
        //将元素放到tail位置上
        elems[tail] = elem;
        tail++;
        if(tail>=elems.length){
            //到达末尾就回到开头
            tail=0;
        }
        size++;
    }
    //队列先进先出
    String take(){
        if(size==0){
            //队列空
            return null;
        }
        //取出head指向元素
        String result = elems[head];
        head++;//此时原本head的元素就被排除到有效位置之外
        if(head>=elems.length){
            head=0;
        }
        //head = (head+1)%elems.length;//求余
        size--;
        return result;
    }
}

public class Demo4 {
    public static void main(String[] args) {

    }
}
